package com.xadmin.sys.rbac.utils;

import com.xadmin.sys.rbac.vo.MenuVo;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author vic Ly
 */
public class FindChild {
    public static List<MenuVo> findMenuChild(Integer id, List<MenuVo> menuVoList){
        List<MenuVo> childList = new ArrayList();
        for(MenuVo menuVoChild : menuVoList){
            if(menuVoChild.getParentId().equals(id)){
                childList.add(menuVoChild);
            }
        }
        //递归
        for (MenuVo nav : childList) {
            nav.setChildren(findMenuChild(nav.getId(), menuVoList));
        }
        //如果节点下没有子节点，返回一个空List（递归退出）
        if(childList.size() == 0){
            return new ArrayList<MenuVo>();
        }
        return childList;

    }
}
